package com.project.app.system;

import com.project.common.annotation.Log;
import com.project.common.core.controller.BaseController;
import com.project.common.core.domain.AjaxResult;
import com.project.common.core.domain.entity.SysUser;
import com.project.common.core.domain.entity.SysUserWx;
import com.project.common.core.page.TableDataInfo;
import com.project.common.enums.BusinessType;
import com.project.system.service.ISysUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("app/system/user")
public class sysUser extends BaseController {

    @Resource
    private ISysUserService sysUserService;

    /**
     * 根据用户电话号码获取详细信息
     */
    @GetMapping(value = "/{phoneNumber}")
    public AjaxResult getByPhone(@PathVariable String phoneNumber) {
        return AjaxResult.success(sysUserService.selectUserByPhoneNumber(phoneNumber));
    }

    /**
     * 查询用户信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SysUser sysUser) {
        startPage();
        List<SysUser> list = sysUserService.selectUserByUserType(sysUser);
        return getDataTable(list);
    }

    /**
     * 修改用户信息
     */
    @Log(title = "用户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody SysUser sysUser) {
        return toAjax(sysUserService.updateUser(sysUser));
    }
}
